package sample.model;

import javafx.beans.property.SimpleStringProperty;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class MonitorFragmentModel {
    private SimpleStringProperty serverName_Monitor = new SimpleStringProperty();//服务器名称
    private SimpleStringProperty hostIP_Monitor = new SimpleStringProperty();//IP地址
    private SimpleStringProperty CpuUse = new SimpleStringProperty();//CpuUse
    private SimpleStringProperty CpuSys = new SimpleStringProperty();//系统cpu
    private SimpleStringProperty CpuWait = new SimpleStringProperty();//cpu wait
    private SimpleStringProperty CpuId = new SimpleStringProperty();//cpu 空闲
    private SimpleStringProperty MemUse = new SimpleStringProperty();//运行队列长度
    private SimpleStringProperty LoadAvg = new SimpleStringProperty();//平均负载
    private SimpleStringProperty LoadAvgReference = new SimpleStringProperty();//平均负载参考

    public MonitorFragmentModel(String serverName_Monitor, String hostIP_Monitor, String CpuUse, String CpuSys, String CpuWait, String CpuId, String MemUse, String LoadAvg, String LoadAvgReference){
        this.serverName_Monitor.set(serverName_Monitor);
        this.hostIP_Monitor.set(hostIP_Monitor);
        this.CpuUse.set(CpuUse);
        this.CpuSys.set(CpuSys);
        this.CpuWait.set(CpuWait);
        this.CpuId.set(CpuId);
        this.MemUse.set(MemUse);
        this.LoadAvg.set(LoadAvg);
        this.LoadAvgReference.set(LoadAvgReference);
    }

    public String getCpuWait() {
        return CpuWait.get();
    }

    public SimpleStringProperty CpuWaitProperty() {
        return CpuWait;
    }

    public void setCpuWait(String CpuWait) {
        this.CpuWait.set(CpuWait);
    }

    public String getserverName_Monitor() {
        return serverName_Monitor.get();
    }

    public SimpleStringProperty serverName_MonitorProperty() {
        return serverName_Monitor;
    }

    public void setserverName_Monitor(String serverName_Monitor) {
        this.serverName_Monitor.set(serverName_Monitor);
    }

    public String gethostIP_Monitor() {
        return hostIP_Monitor.get();
    }

    public SimpleStringProperty hostIP_MonitorProperty() {
        return hostIP_Monitor;
    }

    public void sethostIP_Monitor(String hostIP_Monitor) {
        this.hostIP_Monitor.set(hostIP_Monitor);
    }

    public String getCpuUse() {
        return CpuUse.get();
    }

    public SimpleStringProperty CpuUseProperty() {
        return CpuUse;
    }

    public void setCpuUse(String CpuUse) {
        this.CpuUse.set(CpuUse);
    }

    public String getCpuSys() {
        return CpuSys.get();
    }

    public SimpleStringProperty CpuSysProperty() {
        return CpuSys;
    }

    public void setCpuSys(String CpuSys) {
        this.CpuSys.set(CpuSys);
    }

    public String getCpuId() {
        return CpuId.get();
    }

    public SimpleStringProperty CpuIdProperty() {
        return CpuId;
    }

    public void setCpuId(String CpuId) {
        this.CpuId.set(CpuId);
    }

    public String getMemUse() {
        return MemUse.get();
    }

    public SimpleStringProperty MemUseProperty() {
        return MemUse;
    }

    public void setMemUse(String MemUse) {
        this.MemUse.set(MemUse);
    }

    public String getLoadAvg() {
        return LoadAvg.get();
    }

    public SimpleStringProperty LoadAvgProperty() {
        return LoadAvg;
    }

    public void setLoadAvg(String LoadAvg) {
        this.LoadAvg.set(LoadAvg);
    }

    public String getLoadAvgReference() {
        return LoadAvgReference.get();
    }

    public SimpleStringProperty LoadAvgReferenceProperty() {
        return LoadAvgReference;
    }

    public void setLoadAvgReference(String LoadAvgReference) {
        this.LoadAvgReference.set(LoadAvgReference);
    }

    public String toString(){
        String str= ResultFormat(this.serverName_Monitor.getValue())+"\t"+
                    ResultFormat(this.hostIP_Monitor.getValue())+"\t"+
                    ResultFormat(this.CpuUse.getValue())+"\t"+
                    ResultFormat(this.CpuSys.getValue())+"\t"+
                    ResultFormat(this.CpuWait.getValue())+"\t"+
                    ResultFormat(this.CpuId.getValue())+"\t"+
                    ResultFormat(this.MemUse.getValue())+"\t"+
                    ResultFormat(this.LoadAvg.getValue())+"\t"+
                    ResultFormat(this.LoadAvgReference.getValue());
        return str;
    }

    //去掉一个字符串中的换行符、回车符等，将连续多个空格替换成一个空格
    public static String ResultFormat(String string){
        Pattern p = Pattern.compile("\t|\r|\n");
        Matcher m = p.matcher(string);
        string = m.replaceAll("");
        string = string.replaceAll(" +", " ");
        return string;
    }

}
